# -*- coding:utf-8 -*-
"""
Created on 10 jun 2012

@author: Olof Manbo
"""

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template


import os


class MainPage(webapp.RequestHandler):
    
    
    def get(self):
        user = users.get_current_user()

        if user:
            if users.is_current_user_admin():
                path = os.path.join(os.path.dirname(__file__), 'html/index.html')
                data = {
                        "logoutUrl": users.create_logout_url("/"),}
                self.response.out.write(template.render(path, data))
    #            self.response.out.write(
    #                'Hello %s <a href="%s">Sign out</a><br>Is administrator: %s' % 
    #                (user.nickname(), users.create_logout_url("/"), users.is_current_user_admin())
    #            )
            else:
                self.response.out.write("You are not allowed to play this game.")
        else:
            self.redirect(users.create_login_url(self.request.uri))
